package com.fengmi.mapper;

import com.fengmi.entity.SysUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 作者：陈学虎
 * 时间：2021/7/14 0014 上午 9:20
 */
@Mapper
public interface UserMapper {

    @Select("select * from sys_user where account = #{account} ")
    SysUser findByAccount(String account);

    @Select("select\n" +
            "     sr.role_name\n" +
            "from sys_user user\n" +
            "left join sys_user_role sur on user.user_id = sur.user_id\n" +
            "left join sys_role sr on sur.role_id = sr.role_code\n" +
            "where user.account = #{account} ")
    List<String> findRole(String account);

    @Select("select\n" +
            "     sp.perm_name\n" +
            "from sys_user user\n" +
            "left join sys_user_role sur on user.user_id = sur.user_id\n" +
            "left join sys_role sr on sur.role_id = sr.role_code\n" +
            "left join sys_role_permission srp on sr.role_code = srp.role_id\n" +
            "left join sys_permission sp on srp.perm_id = sp.perm_code\n" +
            "where user.account = #{account} ")
    List<String> findPermission(String account);
}
